<%@ page import="top.fyxxxx.dbdesign.dao.DBoperate" %>
<%@ page import="top.fyxxxx.dbdesign.data.Course" %>
<%@ page import="top.fyxxxx.dbdesign.data.PersonalData" %>
<%@ page import="top.fyxxxx.dbdesign.data.SignInTask" %>
<%@ page import="top.fyxxxx.dbdesign.util.Manager" %>
<%@ page import="top.fyxxxx.dbdesign.util.Reporter" %>
<%@ page import="top.fyxxxx.dbdesign.util.TaskManager" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Set" %><%--
  Created by IntelliJ IDEA.
  User: WZL
  Date: 2020/5/4
  Time: 23:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%
    double process=0;
%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Information</title>
    <link rel="stylesheet" type="text/css" href="inf.css">
    <link rel="stylesheet" type="text/css" href="bar.css">
    <link rel="stylesheet" type="text/css" href="boxAndButton.css">
</head>
<body style="text-align: center">
<%
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    DBoperate dBoperate=DBoperate.getInstance();
    Reporter reporter=Reporter.getInstance();
    TaskManager taskManager=Manager.taskManager();
    if(session.getAttribute("uid")==null)request.getRequestDispatcher("/index.jsp").forward(request,response);
    long uid=(Long)session.getAttribute("uid");
    //long uid=1590064934429L;
    //long uid=1589980575815L;
    session.setAttribute("uid",uid);
%>

<div class="createClassBox" >
    <button   type="submit" value="提交" onclick="location='teacherMainPage.jsp'">管理</button>
</div>
<div class="logoutBox" >
    <button   type="submit" value="提交" onclick="location='index.jsp?un=1'">注销</button>
</div>
<div id="content">
    <div style="text-align: center">
        <p class="title">签到信息</p>
    </div>
    <hr>
    <%
        List<SignInTask> signInTasks=taskManager.getCurTask(uid);
        for(SignInTask signInTask:signInTasks){
            long cid=signInTask.getBelongToCid();
    %>
    <div style="width: 100%">
        <p class="title" style="text-align: left"><%=dBoperate.getCourse(cid).getName()%></p>
        <br>
        <%
            long sid=signInTask.getSid();
            if(reporter.issignin(uid,sid)){
        %>
        <div class="joinedBox" >
            <button    >已签到</button>
        </div>
        <%
        }
        else if (reporter.checkAdmin(uid,cid)){
        %>
        <div class="joinBox" >
            <button    onclick="location='assignments.jsp?sid=<%=sid%>&cid=<%=cid%>'">修改</button>
        </div>
        <%
        }
        else{
        %>
        <div class="joinBox" >
            <button    onclick="location='signin.jsp?sid=<%=sid%>'">签到</button>
        </div>
        <%
            }
            String inf[]=reporter.getSignInTaskInformation(sid);
        %>
        <p class="mainBody">发起人：<%=inf[0]%><br>签到开始时间:<%=inf[1]%><br>签到截止时间:<%=inf[2]%>
        </p>
        <hr>
    </div>
    <%
        }
    %>
</div>
<div id="content"  style="text-align: left">
    <div style="text-align: center">
        <p class="title"><%=dBoperate.getAccountByUid(uid).getName()%></p>
    </div>
    <section class="container">
        <%
            Set<Long> cidSet=dBoperate.getJoinCids(uid);
            for(Long cid:cidSet){
                Course course=dBoperate.getCourse(cid);
                PersonalData personalData=reporter.getPersonalData(uid,uid,cid);
                String t="";
                int siginNum=personalData.getSignInNum();
                int unsiginNum=personalData.getUnSignInNum();
                process=(double)siginNum/(siginNum+unsiginNum);
                if(siginNum+unsiginNum==0)process=1;
                if (process<0.6-1e-8)t="red";
                else if(process<1-1e-8)t="yellow";
                else t="green";
        %>
        <a style="text-decoration:none" href="informationDetail.jsp?cid=<%=cid%>&uid=<%=uid%>"><%=personalData.getCourse().getName()%></a>      <p style="font-size: 10px;float: right">签到次数:<%=siginNum%>次  未签到次数<%=unsiginNum%>次</p>
        <div class="progress">
            <span class="<%=t%>" style="width: <%=process*100%>%"><span><%=process*100%>%</span></span>
        </div>
        <div class="deleteBox" >
            <button    onclick="
                    location='DeleteServlet?cid=<%=cid%>'
                    "><%=(course.getCreateByUid()==uid)?"删除课程":"退出课程"%></button>
        </div>
        <br>
        <br>
        <br>
        <hr>
        <br>
        <%
            }
        %>
    </section>

</div>


</body>
</html>
